<template>
  <div style="margin: 10px 10px">
    <div class="content-label"> {{ label }}</div>
    <a-form-model ref="CaseDecisionInterveneForm" :rules="rules" :model="infoForm">
      <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="是否存在该类情况" prop="isexist" >
        <a-switch v-model="infoForm.isexist" :disabled="isDiasbled" />
      </a-form-model-item>
      <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="干预人" prop="personradio" >
        <a-checkbox-group v-model="infoForm.personradio" :disabled="isDiasbled || !infoForm.isexist">
          <a-checkbox :value="Tp_intervene_personValue.SELF">
            案件当事人或其代理人
          </a-checkbox>
          <a-checkbox :value="Tp_intervene_personValue.WORK">
            行政复议工作人员
          </a-checkbox>
          <a-checkbox :value="Tp_intervene_personValue.LAW">
            司法行政机关工作人员
          </a-checkbox>
          <a-checkbox :value="Tp_intervene_personValue.OTHER" style="margin-top: 10px;">
            其他
            <a-input :maxLength="100" v-model="infoForm.personother" :disabled="isDiasbled || !infoForm.isexist" v-if="infoForm.personradio && infoForm.personradio.includes(Tp_intervene_personValue.OTHER)" style="width:300px;margin-left: 10px;" />
          </a-checkbox>
        </a-checkbox-group>

      </a-form-model-item>
      <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="干预内容" prop="contentradio" >
        <a-checkbox-group v-model="infoForm.contentradio" :disabled="isDiasbled || !infoForm.isexist">
          <a-checkbox :value="Tp_intervene_contentValue.DELEGATE">
            请托说情
          </a-checkbox>
          <a-checkbox :value="Tp_intervene_contentValue.PROGRAM">
            干预办案程序
          </a-checkbox>
          <a-checkbox :value="Tp_intervene_contentValue.RESULT">
            干预复议结果
          </a-checkbox>
          <a-checkbox :value="Tp_intervene_contentValue.OTHER" style="margin-top: 10px;">
            其他
            <a-input :maxLength="100" v-model="infoForm.contentother" :disabled="isDiasbled || !infoForm.isexist" v-if="infoForm.contentradio && infoForm.contentradio.includes(Tp_intervene_contentValue.OTHER)" style="width:300px;margin-left: 10px;" />
          </a-checkbox>
        </a-checkbox-group>

      </a-form-model-item>
      <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="具体情况：" prop="detail" >
        <a-input :maxLength="100" type="textarea" :disabled="isDiasbled || !infoForm.isexist" v-model="infoForm.detail" :style="{ width: 100, marginLeft: 10 }" />
      </a-form-model-item>
      <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="签署人" prop="sign" >
        <a-input :maxLength="100" v-model="infoForm.sign" :disabled="isDiasbled" style="width: 200px; margin-left: 10px;" placeholder="请输入签署人" />
      </a-form-model-item>
      <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="签署日期" prop="signdate" >
        <a-date-picker
          v-model="infoForm.signdate"
          :disabled="isDiasbled"
          :style="{ width: 'calc(50% - 12px)' }"
          placeholder="请选择签署日期"
          format="YYYY-MM-DD"
          allowClear/>
      </a-form-model-item>
    </a-form-model>
  </div>
</template>

  <script>
  import storage from 'store'
  import { APP_USER, APP_DEPT } from '@/store/mutation-types'
  import { Tp_intervene_contentValue } from '@/enumeration/Tp_intervene_content'
  import { Tp_intervene_personValue } from '@/enumeration/Tp_intervene_person'
  import { nanoid } from 'nanoid'
  import moment from 'moment'
  export default {
    props: {
      faapplyid: {
        type: String,
        required: true
      },
      applyid: {
        type: String,
        required: false
      },
      // 是否主办人
      isMain: {
        type: Boolean,
        required: true
      },
      // 是否禁用
      isDiasbled: {
        type: Boolean,
        required: true
      },
      recordObj: {
        type: Object,
        required: false
      }
    },
    data () {
      return {
        labelCol: { span: 4 }, // label宽
        wrapperCol: { span: 20 }, // 组件宽
        currentUser: storage.get(APP_USER), // 登录人信息
        currentDept: storage.get(APP_DEPT), // 登录人部门
        loading: false, // 按钮显示
        Tp_intervene_contentValue: Tp_intervene_contentValue,
        Tp_intervene_personValue: Tp_intervene_personValue,
        infoForm: {
          id: undefined,
          applyid: undefined,
          faapplyid: undefined,
          isexist: false, // 是否存在该情况
          personradio: [], // 干预人
          personother: undefined, // 干预人其他情况
          contentradio: [], // 干预内容
          contentother: undefined, // 干预内容其他情况
          detail: undefined, // 具体情况
          sign: undefined, // 签名
          signdate: undefined, // 签名时间
          signtype: undefined // 主办人还是协办人
        },
        rules: {
          sign: [{ required: true, message: '请输入签署人', trigger: 'blur' }],
          signdate: [{ required: true, message: '请选择签署日期', trigger: 'change' }],
          isexist: [{ required: true, message: '请选择是否存在该类情况', trigger: 'change' }]
        },
        label: undefined
      }
    },
    created () {
      if (this.isMain) {
        this.label = '主办人填写'
      } else {
        this.label = '协办人填写'
      }
      if (this.recordObj && this.recordObj != null && this.recordObj != undefined) {
        this.infoForm = { ...this.infoForm, ...this.recordObj }
        this.infoForm.faapplyid = this.faapplyid
        this.infoForm.applyid = this.applyid
        if (this.recordObj.personradio) {
          this.infoForm.personradio = this.recordObj.personradio.split(',')
          this.infoForm.personradio = this.infoForm.personradio.map(Number)
        } else {
          this.infoForm.personradio = []
        }
        if (this.recordObj.contentradio) {
          this.infoForm.contentradio = this.recordObj.contentradio.split(',')
          this.infoForm.contentradio = this.infoForm.contentradio.map(Number)
        } else {
          this.infoForm.contentradio = []
        }
        if (this.recordObj.isexist) {
          if (this.recordObj.isexist == 3200) {
            this.infoForm.isexist = true
          } else {
            this.infoForm.isexist = false
          }
        }
        if (!this.infoForm.sign) {
          this.infoForm.sign = this.currentUser.fullname // 签名
        }
        if (!this.infoForm.signdate) {
          this.infoForm.signdate = moment(new Date())// 签名时间
        }
        if (!this.infoForm.id) {
          this.infoForm.id = nanoid()
        }
      } else {
        this.initForm()
      }
    },
    methods: {
      initForm () {
        this.infoForm.id = nanoid()
        this.infoForm.isexist = false // 是否存在该情况
        this.infoForm.personradio = [] // 干预人
        this.infoForm.personother = undefined // 干预人其他情况
        this.infoForm.contentradio = [] // 干预内容
        this.infoForm.contentother = undefined // 干预内容其他情况
        this.infoForm.detail = undefined // 具体情况
        this.infoForm.sign = this.currentUser.fullname // 签名
        this.infoForm.signdate = moment(new Date()) // 签名时间
        this.infoForm.sign = undefined // 签名
        this.infoForm.signdate = undefined // 签名时间

        this.infoForm.faapplyid = this.faapplyid
        this.infoForm.applyid = this.applyid
      },
      validate () {
        let validateResult = false
        this.$refs.CaseDecisionInterveneForm.validate((valid) => {
          validateResult = valid
        })
        return validateResult
      },
      getFormData () {
        const formData = JSON.parse(JSON.stringify(this.infoForm))
        if (formData.isexist) {
          formData.isexist = 3200
        } else {
          formData.isexist = 3201
        }
        if (this.isMain) {
          formData.signtype = 3200 // 主办人还是协办人
          formData.applyid = undefined
        } else {
          formData.signtype = 3201
        }
        if (this.infoForm.personradio && this.infoForm.personradio.length > 0) {
          formData.personradio = this.infoForm.personradio.join(',')
        } else {
          formData.personradio = ''
        }
        if (this.infoForm.contentradio && this.infoForm.contentradio.length > 0) {
          formData.contentradio = this.infoForm.contentradio.join(',')
        } else {
          formData.contentradio = ''
        }
        return formData
      },
    }
  }
  </script>

  <style lang="less" scoped>

  :v-deep .ant-descriptions-title {
    text-align: center;
  }
  .content-label {
    color: rgba(0, 0, 0, 0.85);
    font-weight: bold;
    font-size: 16px;
    line-height: 1.5;
    text-align: center;
  }
  </style>
